/*
 * SPI testing utility (using spidev driver)
 *
 * Copyright (c) 2007  MontaVista Software, Inc.
 * Copyright (c) 2007  Anton Vorontsov <avorontsov@ru.mvista.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License.
 *
 * Cross-compile with cross-gcc -I/path/to/cross-kernel/include
 */

#include "my_test_spi.h"
#include"spi_tx_rx.h"
#include "w5500_set.h"
#include "w5500.h"

char   *spiDev0  = (char*)"/dev/spidev0.0" ;//ETH2
char   *spiDev1  = (char*)"/dev/spidev2.0" ;//ETH3

int main(int argc, char *argv[])
{
	system(" echo out > /sys/class/gpio/gpio95/direction");
    system(" echo out > /sys/class/gpio/gpio93/direction");
	reset_w5500();
	int ret = 0;
	struct spidev_t spidev2,spidev3;
	set_spidev(&spidev3,spiDev1,0,8,500000,0);
	int fd=open_spidev(&spidev3);
	spi_init(fd,spidev3.mode,spidev3.bits,spidev3.speed);
	PHY_check(fd);
	// printf("spi mode: 0x%x\n", spidev3.mode);
	// printf("bits per word: %d\n", spidev3.bits);
	// printf("max speed: %d Hz (%d KHz)\n", spidev3.speed,spidev3.speed/1000);

	// transfer(fd,&spidev);

	iinchip_init(fd);
	set_w5500_mac(fd,0);
	set_w5500_ip(fd,0);
	socket_buf_init(txsize, rxsize,fd);
	printf("初始化完成\r\n");

	while(1)                            /*循环执行的函数*/ 
	{
		do_tcp_server(fd,0);                  /*TCP_Client 数据回环测试程序*/
		// do_tcp_server(fd,1);
		// do_tcp_server(fd,2);
		// do_tcp_server(fd,3);                  /*3 error*/
		// do_tcp_server(fd,4);
		// do_tcp_server(fd,5);
		// do_tcp_server(fd,6);                  /*TCP_Client 数据回环测试程序*/
		// do_tcp_server(fd,7);
		// do_tcp_client(fd,0);
	}
	close(fd);

	return ret;
}